package de.syfy.project.game;

import de.syfy.project.engine.Animation;
import de.syfy.project.engine.Texture;
import de.syfy.project.engine.interfaces.Game;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lwjgl.input.Keyboard;

public class Player extends CharacterModel {

    //Unschön jedoch erstmal so für dich Felix!, ich erkläre dir später was
    //du tun kannst.
    Game game;
    
    public Player(Game game) {
        super(game);
        animations(game);
        this.game = game;
    }
    
    @Override
    public void doLogic(long delta){
        super.doLogic(delta);
        if(Keyboard.isKeyDown(Keyboard.KEY_J)){
            
            this.charakter.punch.use();
            
        }
        if(Keyboard.isKeyDown(Keyboard.KEY_K)){
            
            System.out.println("KOMBO!");
        }
        if(Keyboard.isKeyDown(Keyboard.KEY_W)){
            playAnimation("walk_nord");
            this.face = Direction.NORD;
            this.pos.y -= charakter.getCharValue().getMovementSpeed();
            game.getActualWorld().setActualCoordinate(pos);
        }
        if(Keyboard.isKeyDown(Keyboard.KEY_S)){
             playAnimation("walk_sued");
             this.face = Direction.SUED;
             this.pos.y += charakter.getCharValue().getMovementSpeed();
             game.getActualWorld().setActualCoordinate(pos);
             
        }
        if(Keyboard.isKeyDown(Keyboard.KEY_A)){
            this.face = Direction.WEST;
            playAnimation("walk_west");
            this.pos.x -= charakter.getCharValue().getMovementSpeed();
            game.getActualWorld().setActualCoordinate(pos);
            
        }
        if(Keyboard.isKeyDown(Keyboard.KEY_D)){
             this.face = Direction.OST;
             playAnimation("walk_ost");
             this.pos.x += charakter.getCharValue().getMovementSpeed();
             game.getActualWorld().setActualCoordinate(pos);
        }
        if (!(Keyboard.isKeyDown(Keyboard.KEY_W)
            || Keyboard.isKeyDown(Keyboard.KEY_S)
            || Keyboard.isKeyDown(Keyboard.KEY_A)
            || Keyboard.isKeyDown(Keyboard.KEY_D))){
            switch(this.face){
                case NORD: playAnimation("stand_nord") ; break;
                case SUED: playAnimation("stand_sued"); break;
                case OST: playAnimation("stand_ost") ; break;
                case WEST: playAnimation("stand_west") ; break;
                default: ; break;
            }
                
        }
        
    }

    private void animations(Game game) {
        try {
            Texture[] w_s = new Texture[7];
            Texture[] w_n = new Texture[7];
            Texture[] w_o = new Texture[7];
            Texture[] w_w = new Texture[7];
            Texture[] stand_s = new Texture[2];
            Texture[] stand_n = new Texture[2];
            Texture[] stand_o = new Texture[2];
            Texture[] stand_w = new Texture[2];
            stand_s[0]= game.getTextureLoader().getTexture("animationTest/Character test/LinkGB_stand_front.gif");
            stand_n[0]= game.getTextureLoader().getTexture("animationTest/Character test/LinkGB_stand_back.gif");
            stand_s[1]= stand_s[0];
            stand_n[1]= stand_n[0];
            stand_o[0]= game.getTextureLoader().getTexture("animationTest/Character test/LinkGB_stand_side.gif");
            stand_w[0]= game.getTextureLoader().getTexture("animationTest/Character test/LinkGB_stand_sideM.gif");
            stand_o[1]= stand_o[0];
            stand_w[1]= stand_w[0];
            for (int i = 0; i < 7; i++) {
                w_s[i] = game.getTextureLoader().getTexture("animationTest/Character test/LinkGN_walk_front00"+(i+1)+".gif");
                w_n[i] = game.getTextureLoader().getTexture("animationTest/Character test/LinkGN_walk_back00"+(i+1)+".gif");
                w_o[i] = game.getTextureLoader().getTexture("animationTest/Character test/LinkGN_walk_side00"+(i+1)+".gif");
                w_w[i] = game.getTextureLoader().getTexture("animationTest/Character test/LinkGN_walk_sideM00"+(i+1)+".gif");
            }
            Animation ani_w_s = new Animation();
            Animation ani_stand_n = new Animation();
            Animation ani_w_n = new Animation();
            Animation ani_stand_s = new Animation();
            Animation ani_w_o = new Animation();
            Animation ani_stand_o = new Animation();
            Animation ani_w_w = new Animation();
            Animation ani_stand_w = new Animation();
            
            ani_stand_n.loadTextures(stand_n);
            this.registerAnimation("stand_nord", ani_stand_n);
            
            ani_w_n.loadTextures(w_n);
            this.registerAnimation("walk_nord", ani_w_n);
            
            ani_stand_s.loadTextures(stand_s);
            this.registerAnimation("stand_sued", ani_stand_s);
            
            ani_w_s.loadTextures(w_s);
            this.registerAnimation("walk_sued", ani_w_s);
            
            ani_stand_o.loadTextures(stand_o);
            this.registerAnimation("stand_ost", ani_stand_o);
            
            ani_w_o.loadTextures(w_o);
            this.registerAnimation("walk_ost", ani_w_o);
            
            ani_stand_w.loadTextures(stand_w);
            this.registerAnimation("stand_west", ani_stand_w);
            
            ani_w_w.loadTextures(w_w);
            this.registerAnimation("walk_west", ani_w_w);
            
        } catch (IOException ex) {
            Logger.getLogger(Player.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
}
